package com.example.myapplication.tack_24;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_24.data.DetailsData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

public class DetailActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView img;
    private TextView introduce;
    private TextView shippingMethod;
    private TextView phone;
    private Intent intent;
    private String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_24_activity_detail);
        init();
        getDetail(id);
        exit_();
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DetailActivity.this.finish();
            }
        });
    }

    private void getDetail(String id) {
        String url = "prod-api/api/logistics-inquiry/logistics_company/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, DetailsData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                DetailsData data = (DetailsData)obj;
                if(data.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(DetailActivity.this).load(OkHttpTool.URL+data.getData().getImgUrl()).into(img);
                            introduce.setText(data.getData().getIntroduce());
                            shippingMethod.setText(data.getData().getShippingMethod());
                            phone.setText(data.getData().getPhone());
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        img = findViewById(R.id.img);
        introduce = findViewById(R.id.introduce);
        shippingMethod = findViewById(R.id.shippingMethod);
        phone = findViewById(R.id.phone);
        intent = getIntent();
        id = intent.getStringExtra(Common.COMMON);
    }
}